package edu.jmu.bean.user;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
 * 部门实体类
 * @author Neal
 *
 */
@Entity
@Table(name="T_DEPART")
public class Depart implements Serializable{
	private static final long serialVersionUID = 4834805045208932758L;
	
	
	/**	主键	**/
	private Integer id;
	/**	部门名称  **/
	private String name;	
	/**	部门负责人	**/
	private User principalUser;
	/**	部门固话	**/
	private String telphone;
	/**	部门移动电话	**/
	private String moblephone;
	/**	传真	**/
	private String faxes;
	/**	部门人员	**/
	private Set<User> users = new HashSet<User>();
	/**	所属机构	**/
	private Branch branch;
	
	
	@Id	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=20,nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="principalUser_id")
	public User getPrincipalUser() {
		return principalUser;
	}
	public void setPrincipalUser(User principalUser) {
		this.principalUser = principalUser;
	}
	@Column(length=20)
	public String getTelphone() {
		return telphone;
	}
	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}
	@Column(length=11)
	public String getMoblephone() {
		return moblephone;
	}
	public void setMoblephone(String moblephone) {
		this.moblephone = moblephone;
	}
	@Column(length=20)
	public String getFaxes() {
		return faxes;
	}
	public void setFaxes(String faxes) {
		this.faxes = faxes;
	}
	@OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},mappedBy="depart")
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	@ManyToOne(cascade={CascadeType.REFRESH,CascadeType.PERSIST},optional=false,fetch=FetchType.EAGER)
	@JoinColumn(name="branch_id")
	public Branch getBranch() {
		return branch;
	}
	public void setBranch(Branch branch) {
		this.branch = branch;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Depart other = (Depart) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
